/**
 *
 *
 * 
 *    OSIFBOT
 *    Copyright (C) 2013  etchner jorge@devetch.com
 *
 *    This program is free software: you can  redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package osifbot;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.security.CodeSource;
import java.util.logging.Level;
import java.util.logging.Logger;


public class OSIFBOT {
    
        public static void main(String [ ] args){     
       
        try {            
            CodeSource codeSource = OSIFBOT.class.getProtectionDomain().getCodeSource();
            File jarFile = new File(codeSource.getLocation().toURI().getPath());
            String jarDir = jarFile.getParentFile().getPath();
           

            FileReader fr1 = new FileReader(jarDir+"/config.txt");           
            BufferedReader bf1 = new BufferedReader(fr1);
            
            String buffer;
            buffer = bf1.readLine();
            String url = buffer.split("=", 2)[1];
            buffer = bf1.readLine();
            String host = buffer.split("=", 2)[1];
            buffer = bf1.readLine();
            String userBD = buffer.split("=", 2)[1];
            buffer = bf1.readLine();
            String passbd = buffer.split("=", 2)[1];
            if(passbd.length() == 0) {
                passbd = null;
            }
            buffer = bf1.readLine();
            String nombrebd = buffer.split("=",2)[1];
            buffer = bf1.readLine();
            String nickbot = buffer.split("=", 2)[1];
            buffer = bf1.readLine();
            String loginbot = buffer.split("=", 2)[1];
            buffer = bf1.readLine();
            String passbot = buffer.split("=", 2)[1];
            if(passbot.length() == 0) {
                passbot = null;
            }
            buffer = bf1.readLine();
            String servidorirc = buffer.split("=",2)[1];
            buffer = bf1.readLine();
            String canalirc = buffer.split("=", 2)[1];
            
                        
            InterfazBBDD interfazBD = new InterfazBBDD(userBD,passbd,nombrebd, host);
            InterfazIRC interfazIRC = new InterfazIRC(nickbot, loginbot, passbot, servidorirc,interfazBD,url);
            interfazIRC.setVerbose(true);
            interfazIRC.conectar();
            interfazIRC.joinChannel(canalirc);
        } catch (URISyntaxException ex) {
            Logger.getLogger(OSIFBOT.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(OSIFBOT.class.getName()).log(Level.SEVERE, null, ex);
        } 
        }
    
}
